<script setup>
import { ElButton } from 'element-plus'
import { useDeviceStore } from '../stores/device'
import { defineProps, ref } from 'vue'

const deviceStore = useDeviceStore()

const props = defineProps([
    'id',
    'score',
    'online',
    'msg',
    'useTable',
    'current',
])

const checkDevice = async () => {
    await deviceStore.checkDevice(props.id)
}

const getScore = async () => {
    await deviceStore.getScore(props.id)
}
</script>

<template>
    <div
        class="device-item"
        :class="{ online, 'use-table': useTable, current }"
    >
        <div class="device-name">{{ id }}</div>
        <div class="device-score">{{ score < 0 ? '- -' : score }}</div>
        <div class="device-controls">
            <el-button v-if="!online" @click="checkDevice">检查设备</el-button>
            <el-button v-else type="primary" @click="getScore"
                >获取单机评分</el-button
            >
        </div>
        <div class="device-message">{{ msg }}</div>
    </div>
</template>

<style scoped>
.device-item {
    border-radius: 10px;
    min-width: 200px;
    max-width: 250px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    border: 1px solid #ebeef5;
    margin: 20px;
}

.online {
    border-color: #409eff;
}

.current {
    border-color: #e6a23c;
}

.use-table {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    flex: 1;
    margin: 0;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    padding: 0px 50px;
    border: 1px solid #ebeef5;
    border-radius: 0px;
    border-bottom: none;
}

.use-table:last-child {
    border-bottom: 1px solid #ebeef5;
}

.use-table > div {
    flex: 1;
    padding: 2px 20px;
}

.use-table .device-name,
.use-table .device-score {
    font-size: 1em;
    color: inherit;
    margin: 0;
}

.use-table {
    border-color: #ebeef5;
}

.device-name {
    font-size: 20px;
    color: #409eff;
}

.device-score {
    margin: 20px 0;
    font-size: 50px;
}

.device-message {
    display: inline-block;
    height: 1em;
    line-height: 1em;
    margin-top: 8px;
    font-size: 14px;
    color: #909399;
}

.use-table .device-message {
    margin: 0;
}
</style>
